import numpy as np
import matplotlib.pyplot as plt
from matplotlib.lines import lineStyles

def GenerateFigure(source):
    file = open(source, 'r')
    lines = file.readlines()

    data = []
    for line in lines:
        row = line.split()
        row_data = [float(x) for x in row]
        data.append(row_data)

    fre = np.array([row[0] for row in data])
    es_res = np.array([row[1] for row in data])
    rk4_res = np.array([row[2] for row in data])
    aes_res = np.array([row[3] for row in data])
    acc_res = np.array([row[4] for row in data])
 #   plt.plot(fre, es_res, linestyle='dashed', color='g', label='Euler')
    plt.plot(fre, rk4_res, linestyle='solid', color='b', label='RK4')
    plt.plot(fre, aes_res, linestyle='dashed', color='orange', label='Adv Euler')
    plt.plot(fre, acc_res, linestyle='dotted', color='r', label='Acc')

#生成幅值谱
plt.subplot(2,1,1)
plt.title('frequency')
GenerateFigure('output_FFT.res')
#生成相位谱
plt.subplot(2,1,2)
plt.title('phase')
GenerateFigure('output_PFFT.res')

plt.legend()
plt.show()